﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 3/28/2015 7:30:43 PM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevGrammar.TestBasic
{
	[TestClass]
	public class TestString
	{
		
		String str2 = "work, company| salary$ study, class";

		[TestMethod]
		public void test_compare()
		{
			//Ignore case comparation
			string s1 = "China", s2 = "china";
			Console.WriteLine("Ignore Ordinal Compare Result: 'China' equals 'china'? -- {0}",
							s1.Equals(s2, StringComparison.OrdinalIgnoreCase));
		}

		[TestMethod]
		public void test_replace()
		{
			String str = @"This is \a test string.";

			// It will replace all small 't'
			Console.WriteLine(str.Replace('t', 'm'));

			// Remove all blank space at start or end or among sentence
			Console.WriteLine(str2.Replace(" ", ""));
		}

		[TestMethod]
		public void test_split()
		{
			// Split to get sub string list by delimited characters given
			string[] stringArray = str2.Split(',', '|', '$');
			foreach (string s in stringArray)
				Console.WriteLine(s);

			string s5 = "Heller,David,Tood,,Chefi";
			string[] array5 = s5.Split(',');
			// All empty elements will be removed.
			string[] array55 = s5.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

			// Split by sub string
			string s6 = "I am Heller I am David I am Tood I am Chefi";
			string[] array6 = s6.Split(new string[] { "I am" }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string s in array6)
				Console.WriteLine(s);
		}

		[TestMethod]
		public void test_remove()
		{
			String str = @"This is \a test string.";

			Console.WriteLine(str.Remove(str.Length - 1));	// Remove last char
		}

		[TestMethod]
		public void test_sub_string()
		{
			String str = @"This is \a test string.";

			Console.WriteLine(str.Substring(5));
			Console.WriteLine(str.Substring(str.LastIndexOf("\\")));    // "\a test string."
		}

		[TestMethod]
		public void test_first_letter_upper_and_lower()
		{
			String str = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase("first Name");
			Console.WriteLine(str);

			Console.WriteLine("Test_Lower".ToLower());
			Console.WriteLine("test_upper".ToUpper());
		}

		



	}
}
